// table 简单模板
<template>
  <div class="app-container">
    <div class="table-container">
      <el-table :data="list" v-loading="loading" element-loading-text="加载中" size="small" header-cell-class-name='tableHeader' border stripe fit highlight-current-row>
        <el-table-column type="index" label="#" align="center" min-width="50">
        </el-table-column>
        <el-table-column prop="" label="在线" align="center" min-width="50">
        </el-table-column>
        <el-table-column prop="" label="表头" align="center" min-width="80">
          <template slot-scope="scope">
            <el-tooltip content="直属代理和会员" placement="top">
              <router-link class="link" :to="`/`">路由链接</router-link>
            </el-tooltip>
          </template>
        </el-table-column>

      </el-table>
      <div class="pagination-container" v-if="pagination.totalCount > 0">
        <el-pagination @size-change="handlePageSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage" :page-sizes="[10,20,30,50]" :page-size="params.perpage" :total="pagination.totalCount" layout="total,sizes,prev,pager,next,jumper" background>
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      // 查詢參數
      params: {
        username: null,
        perpage: 10, // 每页数量
      },
      // 分页信息
      pagination: {
        currentPage: 1,
        totalCount: 0,
        defaultPageSize: 10,
      },
      list: null,
      loading: true,
    }
  },
  filters: {},
  computed: {
    ...mapGetters(['info']),
  },
  created() {
    // 拉取数据
    this.fetchData()
  },
  methods: {
    // 获取数据
    fetchData() {
      this.loading = true
      this.$store
        .dispatch('ListLoginHists', {
          params: this.$route.params, // 路由参数
          pagination: this.pagination,
        })
        .then(response => {
          this.loading = false
          this.list = response
        })
    },

    // 当前页变化
    handleCurrentChange(value) {
      this.pagination.currentPage = value
      this.fetchData()
    },

    // 每页显示数量变化
    handlePageSizeChange(value) {
      this.params.perpage = value
      this.fetchData()
    },
  },
  watch: {
    $route(to, from) {
      // 监控路由变化,从新加载数据
      if (to.params !== from.params) {
        console.log(to.params)
      }
    },
  },
}
</script>
<style scoped>
.table-container {
}
.pagination-container {
  padding: 10px 0 0 30px;
}
</style>

